this._originalUrl = url;
this._statusChangedCallback = statusChangedCallback;
this._lastRecheck = 0;
- this._recheckAtExit = false;
+ this._recheckTimeoutId = 0;
this._networkSession = WebKit.NetworkSession.new_ephemeral();
this._networkSession.set_proxy_settings(WebKit.NetworkProxyMode.NO_PROXY, null);
}
vfunc_close_request() {
- if (this._recheckAtExit)
+ if (this._recheckTimeoutId) {
this._statusChangedCallback(PortalHelperResult.RECHECK);
- else
- this._statusChangedCallback(PortalHelperResult.CANCELLED);
+ GLib.source_remove(this._recheckTimeoutId);
+ this._recheckTimeoutId = 0;
+ }
+ this._statusChangedCallback(PortalHelperResult.CANCELLED);
return false;
}
// (but ratelimit the checks, we don't want to spam
// nmcheck.gnome.org for portals that have 10 or more internal
// redirects - and unfortunately they exist)
- // If we hit the rate limit, we also queue a recheck
- // when the window is closed, just in case we miss the
- // final check and don't realize we're connected
- // This should not be a problem in the cancelled logic,
- // because if the user doesn't want to start the login,
- // we should not see any redirect at all, outside this._uri
-
- let now = GLib.get_monotonic_time();
- let shouldRecheck = (now - this._lastRecheck) >
- CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT;
-
- if (shouldRecheck) {
- this._lastRecheck = now;
- this._recheckAtExit = false;
- this._statusChangedCallback(PortalHelperResult.RECHECK);
- } else {
- this._recheckAtExit = true;
+
+ if (this._recheckTimeoutId === 0) {
+ const now = GLib.get_monotonic_time();
+ const timeSinceLastRecheck = this._lastRecheck ? now - this._lastRecheck : 0;
+
+ if (timeSinceLastRecheck > CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT || this._lastRecheck === 0) {
+ this._lastRecheck = now;
+ this._statusChangedCallback(PortalHelperResult.RECHECK);
+ } else {
+ const seconds =
+ (CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT - timeSinceLastRecheck) /
+ GLib.USEC_PER_SEC;
+ this._recheckTimeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, seconds, () => {
+ this._statusChangedCallback(PortalHelperResult.RECHECK);
+ this._recheckTimeoutId = 0;
+ return GLib.SOURCE_REMOVE;
+ });
+ }
}
// Update the URI, in case of chained redirects, so we still